<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="main">
      <el-table ref="singleTable" :data="tableData" highlight-current-row border stripe
        @current-change="handleCurrentChange" style="width: 100%">
        <el-table-column property="user_id" width="50">
        </el-table-column>
        <el-table-column property="order_number" label="订单编号">
        </el-table-column>
        <el-table-column property="order_price" label="订单价格">
        </el-table-column>
        <el-table-column property="pay_status" label="是否付款" filter-placement="bottom-end">
          <template slot-scope="scope">
            <el-tag :type="scope.row.pay_status === '0' ? 'danger' : 'success'" disable-transitions>{{
                scope.row.pay_status === '0' ? '未付款' : '已付款'
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column property="is_send" label="是否发货">
        </el-table-column>
        <el-table-column property="create_time" label="下单时间" :formatter="formatter">
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page.sync="currentPage2" :page-sizes="[5, 10, 20, 50]" :page-size="10"
          layout="sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { OrderAPI } from '@/api';
export default {
  data() {
    return {
      tableData: [],
      currentRow: null,
      currentPage2: 1,
      total: 1,
      num: 10,
    }
  },
  watch: {
    currentPage2: {
      async handler() {
        const res = await OrderAPI({
          pagenum: this.currentPage2,
          pagesize: 10
        })
        this.tableData = res.data.data.goods
      }
    }
  },
  mounted(){
  },
  methods: {
    async getUserList() {
      const res = await OrderAPI({
        pagenum: this.currentPage2,
        pagesize: this.num,
      })
      console.log(res.data)
      this.tableData = res.data.data.goods
      console.log(this.tableData)
      this.total = res.data.data.total
      this.$message({
        message: '获取列表成功',
        type: 'success'
      });
      console.log(res.data.meta.status===200)
      if(res.data.meta.status===200){
        this.$message({
          message: res.data.meta.msg,
          type: 'success'
        });
      }else{
        this.$message.error(res.data.meta.msg);
      }
    },
    onReset(){
      this.getUserList()
    },
    formatter(row) {
      const data = new Date(row.create_time * 1000)
      const YYYY = data.getFullYear()
      const MM = data.getMonth().toString().padStart(2, '0')
      const DD = data.getDate().toString().padStart(2, '0')
      const HH = data.getHours().toString().padStart(2, '0')
      const mm = data.getMinutes().toString().padStart(2, '0')
      const ss = data.getSeconds().toString().padStart(2, '0')
      return YYYY + '-' + MM + '-' + DD + ' ' + HH + ':' + mm + ':' + ss
    },
    
    handleSizeChange(val) {
      this.num=val
      this.getUserList()
    },
    handleCurrentChange(val1) {
      this.currentPage2=val1
      this.getUserList()
    }
  },
  created() {
    this.getUserList()
  },
}
</script>

<style lang="less" scoped>
.el-breadcrumb,.block{
  position: relative;
  z-index: 1;
}
.el-table .warning-row {
  background: green;
}

.main {
  margin-top: 10px;
  padding: 15px;
  box-shadow: inset 0 -3em 3em #fff,
    0 0 0 2px rgb(255, 255, 255),
    0.3em 0.3em 1em rgba(0, 0, 0, 0.3);
}
</style>